//
//  UIBarButtonItem+Extension.swift
//  weibo
//
//  Created by yanghong on 15/12/5.
//  Copyright © 2015年 杨鸿. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
  //  MARK: - UIBarButtonItem 便利构造函数
    convenience init(imgName: String? = nil, title: String? = nil, target: AnyObject?, action: Selector) {
        
        self.init()
        
        let button = UIButton()
        //添加点击事件
        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        if let img = imgName {
        
         button.setImage(UIImage(named: img), forState: UIControlState.Normal)
         button.setImage(UIImage(named: "\(img)_highlighted"), forState: .Highlighted)
        
        }
        if let t = title {
        
            button.setTitle(t, forState: .Normal)
            button.titleLabel?.font = UIFont.systemFontOfSize(15)
            button.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
            button.setTitleColor(UIColor.purpleColor(), forState: .Normal)
            button.sizeToFit()
       
        }
        
        button.sizeToFit()
       customView = button
    }

}
